package com.bank.bank.common.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    //自定义状态码、提示消息、具体数据
    private Integer state;
    private String message;
    private Object data;

    /**
     * 针对于有具体数据返回的控制器方法;
     * @param statusCode
     */
    public JsonResult(StatusCode statusCode, Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    /**
     * 针对于没有具体数据返回的控制器方法
     */
    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    /**
     * 封装静态方法:只针对于每个方法中操作成功的场景
     */
    public static JsonResult ok(){
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }

    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }
}









